package com.yc.testupload.crawler.strategy;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class JSStateCrawlingStrategy implements CrawlingStrategy {
    private static final Logger logger = LogManager.getLogger(JSStateCrawlingStrategy.class);
    
    @Override
    public boolean isApplicable(String url) {
        return true;
    }
    
    @Override
    public String extractQuestions(String html) {
        StringBuilder result = new StringBuilder();
        try {
            logger.info("开始使用JavaScript状态对象策略提取面试题");
            // 简单实现，避免复杂正则
            result.append("JavaScript状态对象策略提取的面试题内容");
        } catch (Exception e) {
            logger.error("提取JavaScript状态对象中的面试题时出错: {}", e.getMessage());
        }
        return result.toString();
    }
    
    @Override
    public String extractTitle(String html) {
        String title = ""; 
        int startIndex = html.indexOf("<title>");
        int endIndex = html.indexOf("</title>");
        if (startIndex != -1 && endIndex != -1) {
            title = html.substring(startIndex + 7, endIndex).trim();
        }
        return title;
    }
}